import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    sum: 30,
    name: "钉钉",
    age: 60,
    sex: "男"
  },
  mutations: {
    Add(state, value) {
      state.sum += 3;
    },
    JIAN(state, value) {
      state.sum -= value;
    },

    ODD(state, value) {
      state.sum += value;
    },
  },
  actions: {
    jian(context, value) {
      context.commit('JIAN', value);
    },
    // 奇数嘉嘉
    Odd(context, value) {
      if (context.state.sum % 2 === 1) {
        context.commit('ODD', value);
      }
    },
  },
  getters: {
    total(state) {
      return state.sum * state.age
    }
  },
  modules: {},
});
